/**
 * Created by Administrator on 2017/3/5 0005.
 */
$(function(){
    // 鎶ュ悕缁勫埆鍜屼綔鍝佸噯纭鏍间簩绾ц仈鍔�
    function objInit(obj){
        return $(obj).html("<option>璇烽€夋嫨</option>");
    }
    var arrData = {
        '鎷夋牸锛圠ager锛�':[
            'German-Style Pilsener',
            'Bohemian-Style Pilsener',
            'European Low-Alcohol Lager/German Leicht(bier)',
            'Mu虉nchner (Munich)-Style Helles',
            'Dortmunder/European-Style Export',
            'Vienna-Style Lager',
            'German-Style Ma虉rzen',
            'German-Style Oktoberfest/Wiesn',
            'European-Style Dark/Mu虉nchner Dunkel',
            'German-Style Schwarzbier',
            'Bamberg-Style Ma虉rzen Rauchbier',
            'Bamberg-Style Helles Rauchbier',
            'Bamberg-Style Bock Rauchbier',
            'Traditional German-Style Bock.',
            'German-Style Heller Bock/Maibock',
            'German-Style Doppelbock',
            'German-Style Eisbock',
            'Kellerbier (Cellar beer) or Zwickelbier 鈥� Lager',
            'American-Style Lager',
            'American-Style Light (Low Calorie) & Low Carbohydrate Lager',
            'American-Style Amber (Low Calorie) Lager',
            'American-Style Pilsener',
            'American-Style Ice Lager',
            'American-Style Malt Liquor',
            'American-Style Amber Lager',
            'American-Style Ma虉rzen/Oktoberfest',
            'American-Style Dark Lager',
            'Baltic-Style Porter',
            'Australasian, Latin American or Tropical-Style Light Lager'
        ],
        '灏忛害锛圵heat锛�':[
            'Belgian-Style White (or Wit)/Belgian-Style Wheat',
            'South German-Style Hefeweizen/Hefeweissbier',
            'South German-Style Kristal Weizen/Kristal Weissbier',
            'German-Style Leichtes Weizen/Weissbier',
            'South German-Style Hefeweizen/Hefeweissbier',
            'South German-Style Bernsteinfarbenes Weizen/Weissbier',
            'South German-Style Dunkel Weizen/Dunkel Weissbier',
            'South German-Style Weizenbock/Weissbock',
            'Bamberg-Style Weiss (Smoke) Rauchbier (Dunkel or Helles',
            'American-Style Wheat Wine Ale',
            'American-Style Wheat Ale'
        ],
        '缇庡紡锛圛PA&PA锛�':[
            "American-Style IPA&PA"
        ],
        '闈炵編寮忥紙IPA&PA锛�':[
            "British-Style IPA&PA",
            "International IPA&PA",
            "Hybrid IPA&PA"
        ],
        '娣¤壊鑹惧皵锛圥ale Ale锛�':[
            "Ordinary Bitter",
            "Special Bitter or Best Bitter",
            "Extra Special Bitter",
            "English-Style Summer Ale",
            "Scottish-Style Light Ale",
            "Scottish-Style Heavy Ale",
            "Scottish-Style Export Ale",
            "English-Style Pale Mild Ale",
            "Old Ale",
            "Strong Ale",
            "Scotch Ale",
            "British-Style Barley Wine Ale",
            "Fresh 鈥淲et鈥� Hop Ale",
            "Pale American-Belgo-Style Ale",
            "American-Style Barley Wine Ale",
            "Golden or Blonde Ale",
            "German-Style Ko虉lsch/Ko虉ln-Style Ko虉lsch",
            "German-Style Brown Ale/Du虉sseldorf-Style Altbier",
            "Kellerbier (Cellar beer) or Zwickelbier 鈥� Ale",
            "Adambier",
            "Grodzisz",
            "International-Style Pale Ale",
            "Australasian-Style Pale Ale",
            "Session Beer ",
            "American-Style Cream Ale",
            "California Common Beer",
            "Japanese Sake-Yeast Beer",
            "Rye Ale or Lager with or without Yeast",
            "German-Style Rye Ale (Roggenbier) with or without Yeast"
        ],
        '娣辫壊鑹惧皵锛圖ark Ale锛�':[
            "Scottish-Style Heavy Ale",
            "Scottish-Style Export Ale",
            "English-Style Dark Mild Ale",
            "English-Style Brown Ale",
            "Old Ale",
            "Strong Ale",
            "Scotch Ale",
            "British-Style Barley Wine Ale",
            "Irish-Style Red Ale",
            "Fresh 鈥淲et鈥� Hop Ale",
            "Dark American-Belgo-Style Ale",
            "American-Style Amber/Red Ale",
            "Imperial or Double Red Ale",
            "American-Style Barley Wine Ale",
            "American-Style Brown Ale",
            "German-Style Brown Ale/Du虉sseldorf-Style Altbier",
            "Kellerbier (Cellar beer) or Zwickelbier 鈥� Ale",
            "Adambier",
            "Rye Ale or Lager with or without Yeast",
            "German-Style Rye Ale (Roggenbier) with or without Yeast "
        ],
        '涓栨稕/娉㈢壒 锛圫tout/Porter锛�':[
            "Brown Porter",
            "Robust Porter ",
            "Sweet Stout or Cream Stout",
            "Oatmeal Stout",
            "Classic Irish-Style Dry Stout",
            "Foreign (Export)-Style Stout",
            "Porter",
            "Smoke Porter",
            "American-Style Black Ale",
            "American-Style Stout",
            "American-Style Imperial Stout",
            "Specialty Stouts",
            "American-Style Imperial Porter",
            "Porter"
        ],
        '姣斿埄鏃舵贰鑹� Belgian-Style Pale Ale':[
            "Belgian-Style Flanders Oud Bruin or Oud Red Ales",
            "Belgian-Style Dubbel",
            "Belgian-Style Tripel",
            "Belgian-Style Quadrupel",
            "Belgian-Style Blonde Ale",
            "Belgian-Style Pale Ale",
            "Belgian-Style Pale Strong Ale",
            "Belgian-Style Dark Strong Ale",
            "Belgian-Style Table Beer",
            "Other Belgian-Style Ales",
            "French-Style Bie虁re de Garde",
            "French & Belgian-Style Saison"
        ],
        '姣斿埄鏃舵繁鑹� Belgian-Style Dark Ale':[
            "姣斿埄鏃舵繁鑹� Belgian-Style Dark Ale",
            "Belgian-Style Dubbel",
            "Belgian-Style Tripel",
            "Belgian-Style Quadrupel",
            "Belgian-Style Pale Strong Ale",
            "Belgian-Style Dark Strong Ale",
            "French-Style Bie虁re de Garde",
            "French & Belgian-Style Saison"
        ],
        '澧炲懗锛圫pecialty锛�':[
        ],
        '璇曢獙缁勶紙Experimental锛�':[
        ]
    };
    //$.each(arrData,function(pF) {
    //    $("#selF").append("<option>"+pF+"</option>");
    //});
    //$("#selF").change(function() {
    //    objInit("#selT");
    //    $.each(arrData,function(pF, pS) {
    //        if ($("#selF option:selected").text() == pF) {
    //            $.each(pS,function(pT,pC) {
    //                $("#selT").append('<option value="'+this+'">'+this+'</option>');
    //            });
    //        };
    //    });
    //});

    // 琛ㄥ崟楠岃瘉
    $("form .required").each(function(){
        $(this).blur(function(){
            var $parent = $(this).siblings('h3');
            if($(this).hasClass('addText')){
                if(this.value==""){
                    var errorMsg = '璇峰～鍐�';
                    $parent.append('<span class="formtips onError">'+errorMsg+'</span>');
                }
            }
            if ($(this).hasClass('sele_opti')) {
                if(this.value==0){
                    var errorMsg = '璇烽€夋嫨';
                    $parent.append('<span class="formtips onError">'+errorMsg+'</span>');
                }
            }
            if($(this).hasClass('apply_bie')){
                if(this.value==0){
                    var errorMsg = '璇烽€夋嫨';
                    $parent.append('<span class="formtips onError">'+errorMsg+'</span>');
                }
            }
            if($(this).hasClass('area_text')){
                var txt = $(this).val();
                if(txt==""){
                    var errorMsg = '璇峰～鍐�';
                    $parent.append('<span class="formtips onError">'+errorMsg+'</span>');
                }
            }

            if ($(this).is('#phone')) {
                if(this.value==""||(this.value!=""&&!/^[0-9]{11}$/.test(this.value))){
                    var errorMsg = '璇疯緭鍏ユ纭殑鎵嬫満鍙风爜';
                    $parent.append('<span class="formtips onError">'+errorMsg+'</span>');
                }
            }
            if ($(this).is('#province')) {
                if(this.value==0){
                    var errorMsg = '璇烽€夋嫨';
                    $parent.append('<span class="formtips onError">'+errorMsg+'</span>');
                }
            }
        });
    })
    $("form .required").focus(function(){
        var $parent = $(this).siblings('h3');
        $parent.find(".formtips").remove();
    });


    /**
     * ajax 涓婁紶鍥剧墖
     * zhaoly@11space.com
     */
    var xhr;

    function createXMLHttpRequest() {
        if (window.ActiveXObject) {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        } else if (window.XMLHttpRequest) {
            xhr = new XMLHttpRequest();
        }
    }

    function UpladFile() {
        var fileObj = document.getElementById("photo").files[0];
        var FileController = './doajaxfileupload.php';
        var form = new FormData();
        form.append("myfile", fileObj);
        createXMLHttpRequest();
        xhr.onreadystatechange = handleStateChange;
        xhr.open("post", FileController, true);
        xhr.send(form);
    }

    function handleStateChange() {
        if (xhr.readyState == 4) {
            if (xhr.status == 200 || xhr.status == 0) {
                var result = xhr.responseText;
                var json = eval("(" + result + ")");
                $("#myphoto").val(json.file);
                // alert('鍥剧墖閾炬帴:\n' + json.file);
            }
        }
    }

    $("#photo").on("change",function(){
        UpladFile();
    })



    $("#send").click(function(){
        var $parent = $(this).parents('form');
        $parent.find(".formtips").remove();
        $("form .required").trigger('blur');
        var numError = $('form .onError').length;
        if(numError){
            return false;
        }
        $.ajax({
            type : "POST",
            url:"./apply.php",//+tab,
            data : $('#myform').serialize(),// 浣犵殑formid
            dataType: "json",
            success: function(data){
                if(data.status == 1) {
                    layer.msg(data.msg)
                    $(function () {
                        setTimeout( 'window.location.href = "index.php"' ,2000);
                    })

                } else {
                    layer.msg(data.msg)
                }
            }
        })


    });


    //鐪佷唤
    var pro = ["娴峰","鍖椾含","澶╂触","涓婃捣","閲嶅簡","娌冲寳","灞辫タ","杈藉畞","鍚夋灄","榛戦緳姹�","姹熻嫃","娴欐睙","瀹夊窘","绂忓缓","姹熻タ","灞变笢","娌冲崡","婀栧寳","婀栧崡","骞夸笢","娴峰崡","鍥涘窛","璐靛窞","浜戝崡","闄曡タ","鐢樿們","闈掓捣","鍐呰挋鍙�","骞胯タ","瑗胯棌","瀹佸","鏂扮枂缁村惥灏旇嚜娌诲尯","棣欐腐","婢抽棬","鍙版咕"];
    for(var i=0;i<pro.length;i++){
        $option=$("<option/>")
        $option.attr("value",pro[i]);
        $option.text(pro[i]);
        $("#province").append($option);
    }

    $('#selF').change(function(){
        var classStr = 'pid'+$(this).val();
        var arr = new Array();
        $('.'+classStr).each(function(k,v) {
            arr[k] = $(this).html()
        })
        $('#selT').empty().append(arr)
    })
})








